package nsu.edu.zsq.controller.teacher;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;

import nsu.edu.zsq.bean.Message;
import nsu.edu.zsq.bean.Teacher;
import nsu.edu.zsq.common.JsonData;
import nsu.edu.zsq.common.RequestHolder;
import nsu.edu.zsq.param.PageQuery;
import nsu.edu.zsq.service.sys.MessageService;
import nsu.edu.zsq.service.teacher.PersonalInfoService;

/** 
* Description: 教师自身信息的controller类<br>
*/
@Controller
@RequestMapping("/teacher/info")
public class PersonalInfoController {
     
	@Autowired
    private MessageService messageService;
    @Autowired
    private PersonalInfoService personalInfoService;
        
    /**
     * 到达教师的个人信息页面
     * @param model
     * @return String teacher/teacher_info.html
     */
    @RequestMapping("/toTeacher_info")
    public String toTeacherInfo(Model model) {
        Teacher teacher = RequestHolder.getCurrentTeacher();
        model.addAttribute("teacher", teacher);
        return "teacher/info/teacher_info.html";
    }
    
    /**
     * 更新教师登录密码
     * @param password 密码
     * @return JsonData
     */
    @RequestMapping("/updatePassword")
    @ResponseBody
    public JsonData updatePassword(@RequestParam("password")String password) {
        personalInfoService.updatePassword(password);
        return JsonData.success();
    }
    
    // =================================个人信息管理================================
    
    /**
     * 跳转到教师个人在职信息页面，携带教师个人信息
     * @param model
     * @return String teacher/info/teacher_joinInfo.html
     */
    @RequestMapping("/toTeacher_joinInfo")
    public String toTeacher_joinInfo(Model model) {
        model.addAttribute("teacher", RequestHolder.getCurrentTeacher());
        return "teacher/info/teacher_joinInfo.html";
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /**
     * @param model 
     * @return String teacher/teacher_welcome.html
     */
    @RequestMapping("/toTeacher_welcome")
    public String toTeacher_welcome(Model model) {
        Message message = messageService.getTopMessage();
        model.addAttribute("message", message);
        model.addAttribute("teacher", RequestHolder.getCurrentTeacher());
        return "teacher/teacher_welcome.html";
    }

    /**
     * @param PageQuery 分页数据
     * @return JsonData
     */
    @RequestMapping("/listMessage")
    @ResponseBody
    public JsonData listMessage(PageQuery pageQuery) {
        PageInfo<Message> listMessage = personalInfoService.listMessageWithPage(pageQuery);
        return JsonData.success(listMessage);
    }
    
    /**
     * @param model 
     * @return String teacher/info/teacher_schoolMsg_detail.html
     */
    @RequestMapping("/toMessageDetail")
    public String toMessageDetail(@RequestParam("id")int id, Model model) {
        Message message = messageService.getMessage(id);
        model.addAttribute("message", message);
        return "teacher/info/teacher_schoolMsg_detail.html";
    }
}
